<template>
  <div>
    <TopFilter :list="topFilterList" :collapse="false" @filterChange="changeHandle"
               @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      height="400"
      :selectionType="selectionType"
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="getfetchParams"
      datakey="records"
      :onColumnsChange="columns => (this.columns = columns)"
      :onSyncTableData="tableChangeFun"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>
    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="submitBtn">确定
      </el-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeDialog">取消
      </el-button>
    </div>
  </div>
</template>

<script>
import {dictionary} from '@/utils/dictMixin';
import {getBatteryMaintenanceList} from '@/api/partsmanage/batteryTrace/batteryMaintenance';
import {ghnrArr} from "../batteryMaintenance/constant";

export default {
  name: 'addBattery',
  components: {},
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      visible: false,
      fetchApi: getBatteryMaintenanceList,
      pageType: 'addBattery',
      fetchParams: {},
      columns: this.createTableColumns(),
      selectArr: []
    };
  },
  props: {
    selectionType: {},
    params: {
      type: Object,
      default() {
        return {}
      }
    }
  },//'single':'multiple' 单选多选
  computed: {
    getfetchParams() {
      return Object.assign({
        pageType: this.pageType
      }, this.params, this.fetchParams);
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    tableChangeFun(val) {
    },
    selectChange(val) {
      this.selectArr = val
      console.log(val)
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '维修登记单号',
          dataIndex: 'maintenanceCode',
          sorter: true,
        },
        {
          title: 'VIN',
          width: 150,
          dataIndex: 'vin',
          sorter: true,
        },
        {
          title: '经销商名称',
          width: 150,
          dataIndex: 'dealerName',
          sorter: true,
        },
        {
          title: '更换内容',
          dataIndex: 'batterySpecies',
          width: 150,
          sorter: true,
          dictItems: ghnrArr,
        },
        {
          title: '维修日期',
          dataIndex: 'replaceDate',
          sorter: true,
        },
        {
          title: '电池包编码',
          dataIndex: 'oldCode',
          sorter: true,
        },
        {
          title: '电池模块编码',
          dataIndex: 'oldModuleCode',
          sorter: true,
        },
        {
          title: '电芯编码',
          dataIndex: 'oldCellCode',
          sorter: true,
        },
        {
          title: '客户姓名',
          dataIndex: 'customerName',
          sorter: true,
        },
        {
          title: '客户联系电话',
          dataIndex: 'customerPhone',
          sorter: true,
        },
      ]
    },
    createTopFilterList() {
      return [
        {type: 'INPUT', label: '电池包编码', fieldName: 'oldCode', placeholder: '请输入'},
        {type: 'INPUT', label: '电池模块编码', fieldName: 'oldModuleCode', placeholder: '请输入'},
        {type: 'INPUT', label: '电芯编码', fieldName: 'oldCellCode', placeholder: '请输入'},
      ];
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = {...this.fetchParams};
      }
    },
    closeDialog() {
      this.$emit('closeDialog')
    },
    submitBtn() {
      if (this.selectArr.length == 0) {
        this.$notify.warning({title: '提示信息', message: '请选择'});
        return
      }
      this.$emit('selectArr', this.selectArr)
    }
  }
};
</script>

<style lang="less" scoped>
.dialogBottmView {
  text-align: center;
}
</style>
